﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "IWidget.h"
#include "Vector3d.h"
#include "OwnerPtr.h"
#include "ElementId.h"

#include "QDialog"
#include "GRepModule.h"
#include "BaseTreeDlg.h"

class QTreeWidgetItem;

/// 本文件是界面实现的辅助类，不包含GDMP API的演示内容
namespace gcmp
{
    class IDocument;
    class ElementId;
    class IGraphicsNode;
    class IGraphicsElementShape;
}

namespace Sample
{
    class IGraphicsNode_Wrapper;

    class GrepProbeDlg : public BaseTreeDlg
    {
        Q_OBJECT

    public:
        GrepProbeDlg(QWidget *parent = nullptr);
        ~GrepProbeDlg();

        IGraphicsNode_Wrapper* GetDisplayData() { return m_opGraphicsNodeWrapper.get(); }
        // 设置为nullptr时清空浏览器
        void SetDisplayData(gcmp::OwnerPtr<IGraphicsNode_Wrapper> opGraphicsNodeWrapper);

        gcmp::IGraphicsNode* GetSelectedGNode() { return m_selectedGNode; }

        // 获得GrepProbeDlg，可能为空
        static GrepProbeDlg* Get();
        // 获得GrepProbeDlg，为空则创建后返回
        static GrepProbeDlg* GetOrCreate();

        void ShowDock() override;
        void HideDock() override;

        gcmp::ElementId GetElementId();

    protected slots:
        virtual void OnTreeItemSelected() ;

    private:
        void AddNodes(IGraphicsNode_Wrapper* pGNodeWrapper, QTreeWidgetItem* pItem, std::vector<int> location);
    protected:
        virtual QSize sizeHint() const override;
    private:
        gcmp::IDocument* m_pDoc;
        gcmp::IGraphicsNode* m_selectedGNode;

        gcmp::OwnerPtr<IGraphicsNode_Wrapper> m_opGraphicsNodeWrapper;
        std::map<std::wstring, QTreeWidgetItem*> m_itemMap;
    };
}

